package com.example.springbootdemo.controller;

import com.example.springbootdemo.dto.GeoJsonDto;
import com.example.springbootdemo.service.GeoJsonService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("/api/geojson")
@Validated
public class GeoJsonController {

    @Autowired
    private GeoJsonService geoJsonService;

    @PostMapping("/convert")
    public ResponseEntity<byte[]> convertGeoJsonToShp(@Valid @RequestBody GeoJsonDto geoJsonDto) {
        byte[] zipFile = geoJsonService.convertGeoJsonToShp(geoJsonDto);
        return ResponseEntity.ok()
                .header("Content-Disposition", "attachment; filename=output.zip")
                .body(zipFile);
    }
}